package sing.myapp.net.interceptor

import okhttp3.Interceptor
import okhttp3.Response
import sing.core.util.MMkvUtil
import java.io.IOException

/**
 * 自定义头部参数拦截器，传入heads
 */
class MyHeadInterceptor : Interceptor {

    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        val builder = chain.request().newBuilder()

        val token = MMkvUtil().token
        if (token.isNotEmpty()) {
            builder.addHeader("token", token).build()
        }

        return chain.proceed(builder.build())
    }
}